package cn.edu.service.impl;

import cn.edu.mapper.TeacherMapper;
import cn.edu.mapper.dep_TeacherMapper;
import cn.edu.pojo.*;
import cn.edu.service.TeacherService;
import cn.edu.service.dep_TeacherService;
import cn.edu.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

/**
 * @author Davey chan
 */
public  class dep_TeacherServiceImpl implements dep_TeacherService {
    SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();


    @Override
    public PageBean<All> selectByPageAndcondition(int currentPage, int pageSize, All t) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
//      获取mapper对象
        dep_TeacherMapper mapper = sqlSession.getMapper(dep_TeacherMapper.class);
//     计算开始的索引
        int begin=(currentPage-1)*pageSize;
//        计算查询的条目数
        int size =pageSize;
//        处理查询条件，模糊查询
        String teacherName = t.getTeacherName();
        if(teacherName !=null && teacherName.length()>0){
            t.setTeacherName("%"+teacherName+"%");
        }
        String title = t.getTitle();
        if(title !=null && title.length()>0){
            t.setTitle("%"+title+"%");

        }
        t.setExamstatus("3");



        List<All> rows = mapper.selectBypageAndCondtion(begin, size,t);
//        查询总记录数
        int totalCount = mapper.selectTotalCountByCondition(t);
//封装pageBean

        PageBean<All> pageBean=new PageBean<>();
        pageBean.setRows(rows);
        pageBean.setTotalCount(totalCount);

        sqlSession.close();
        return pageBean;
    }

    @Override
    public void delteacher(Integer id) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
//      获取mapper对象
        dep_TeacherMapper mapper = sqlSession.getMapper(dep_TeacherMapper.class);
//     计算开始的索引
        mapper.delteacher(id);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void Updateteach_work(teach_work t) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
//      获取mapper对象
        dep_TeacherMapper mapper = sqlSession.getMapper(dep_TeacherMapper.class);
//     计算开始的索引
        mapper.UpdateTeach_work(t);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void UpdateAnnual_examination(annual_examination t) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
//      获取mapper对象
        dep_TeacherMapper mapper = sqlSession.getMapper(dep_TeacherMapper.class);
//     计算开始的索引
        mapper.UpdateAnnual_exam(t);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void UpdatePatent(patent t) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
//      获取mapper对象
        dep_TeacherMapper mapper = sqlSession.getMapper(dep_TeacherMapper.class);
//     计算开始的索引
        mapper.UpdatePatent(t);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void UpdateOpus(opus t) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
//      获取mapper对象
        dep_TeacherMapper mapper = sqlSession.getMapper(dep_TeacherMapper.class);
//     计算开始的索引
        mapper.UpdateOpus(t);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void UpdateThesis(thesis t) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
//      获取mapper对象
        dep_TeacherMapper mapper = sqlSession.getMapper(dep_TeacherMapper.class);
//     计算开始的索引
        mapper.UpdateThesis(t);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void UpdateTrain(train t) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
//      获取mapper对象
        dep_TeacherMapper mapper = sqlSession.getMapper(dep_TeacherMapper.class);
//     计算开始的索引
        mapper.UpdateTrain(t);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void UpdateWork(work t) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
//      获取mapper对象
        dep_TeacherMapper mapper = sqlSession.getMapper(dep_TeacherMapper.class);
//     计算开始的索引
        mapper.UpdateWork(t);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void UpdateHonor(honor_title t) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
//      获取mapper对象
        dep_TeacherMapper mapper = sqlSession.getMapper(dep_TeacherMapper.class);
//     计算开始的索引
        mapper.UpdateHonor(t);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void UpdateAward(award t) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
//      获取mapper对象
        dep_TeacherMapper mapper = sqlSession.getMapper(dep_TeacherMapper.class);
//     计算开始的索引
        mapper.UpdateAward(t);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void UpdateResearch_project(research_project t) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
//      获取mapper对象
        dep_TeacherMapper mapper = sqlSession.getMapper(dep_TeacherMapper.class);
//     计算开始的索引
        mapper.UpdateResearch_project(t);
        sqlSession.commit();
        sqlSession.close();
    }


}
